package me.zhengjie.modules.system.rest;/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import me.zhengjie.annotation.Log;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import me.zhengjie.modules.system.domain.PokerActivateAwardInfo;
import me.zhengjie.modules.system.domain.PokerActivateInfo;
import me.zhengjie.modules.system.domain.PokerGoodInfo;
import me.zhengjie.modules.system.domain.dto.PokerActivateAwardInfoQueryCriteria;
import me.zhengjie.modules.system.mapper.PokerActivateInfoMapper;
import me.zhengjie.modules.system.mapper.PokerGoodInfoMapper;
import me.zhengjie.modules.system.service.PokerActivateAwardInfoService;
import me.zhengjie.modules.system.service.impl.PokerActivateAwardInfoServiceImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author greazy
* @date 2025-04-09
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "actaward")
@RequestMapping("/api/pokerActivateAwardInfo")
public class PokerActivateAwardInfoController {

    private final PokerActivateAwardInfoService pokerActivateAwardInfoService;

    private final PokerActivateInfoMapper activateInfoMapper;

    private final PokerGoodInfoMapper pokerGoodInfoMapper;

    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    public void exportPokerActivateAwardInfo(HttpServletResponse response, PokerActivateAwardInfoQueryCriteria criteria) throws IOException {
        pokerActivateAwardInfoService.download(pokerActivateAwardInfoService.queryAll(criteria), response);
    }

    @GetMapping
    @ApiOperation("查询actaward")
    public ResponseEntity<Object> queryPokerActivateAwardInfo(Integer activateId ){
        HashMap<String, Object> result = new HashMap<>();
        LambdaQueryWrapper<PokerActivateAwardInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PokerActivateAwardInfo::getActivateId,activateId).orderByAsc(PokerActivateAwardInfo::getRank);
        PokerActivateInfo pokerActivateInfo = activateInfoMapper.selectById(activateId);
        result.put("awardList",pokerActivateAwardInfoService.list(wrapper));
        if (pokerActivateInfo.getJoinGoodId()!=null){
            LambdaQueryWrapper<PokerGoodInfo> goodWrapper = new LambdaQueryWrapper<>();
            goodWrapper.eq(PokerGoodInfo::getGoodId, pokerActivateInfo.getJoinGoodId());
            PokerGoodInfo goodInfo = pokerGoodInfoMapper.selectOne(goodWrapper);
            result.put("joinGoodName",goodInfo.getGoodName());
            result.put("joinGoodNum",pokerActivateInfo.getJoinGoodNum());
        }
        return new ResponseEntity<>(result,HttpStatus.OK);
    }

    @PostMapping
    @Log("新增actaward")
    @ApiOperation("新增actaward")
    public ResponseEntity<Object> createPokerActivateAwardInfo(@Validated @RequestBody PokerActivateAwardInfo resources){
        pokerActivateAwardInfoService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改actaward")
    @ApiOperation("修改actaward")
    public ResponseEntity<Object> updatePokerActivateAwardInfo(@Validated @RequestBody PokerActivateAwardInfo resources){
        pokerActivateAwardInfoService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @GetMapping("delete")
    public ResponseEntity<Object> deletePokerActivateAwardInfo(Integer id) {
        ArrayList<Integer> ids = new ArrayList<>();
        ids.add(id);
        pokerActivateAwardInfoService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}